/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui;

import dao.bophanDAO;
import dao.hanghoaDAO;
import dao.nhanvienDAO;
import java.util.List;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.table.DefaultTableModel;
import org.hibernate.HibernateException;
import pojo.*;

/**
 *
 * @author HoaDinhGiang
 */
public class QuanLyNhanVienInternalFrame extends javax.swing.JInternalFrame {

    /**
     * Creates new form QuanLyNhanVienMatKhauInternalFrame
     */
    private List<Nhanvien> dsNhanVien;
    private DefaultComboBoxModel comboBoxModelLoaiNhanVien;
    protected Nhanvien _TeamOjectNhanVien;
    public int maPhieuXuat;
    private DefaultTableModel dtm;
    public QuanLyNhanVienInternalFrame() {
        initComponents();
        dtm = new DefaultTableModel();
        dtm.addColumn("Mã");
        dtm.addColumn("Tên Nhân Viên");
        dtm.addColumn("Bộ Phận");
        dtm.addColumn("Địa Chỉ");
        dtm.addColumn("Điện Thoại");
        dtm.addColumn("Email");
        dtm.addColumn("Số Tài Khoản");
        dtm.addColumn("Ngân Hàng");
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtbNhanVien = new javax.swing.JTable();
        jtfDienThoai = new javax.swing.JTextField();
        jtfEmail = new javax.swing.JTextField();
        jtfNganHang = new javax.swing.JTextField();
        jcbBoPhan = new javax.swing.JComboBox();
        jtfMaNhanVien = new javax.swing.JTextField();
        jtfTenNhanVien = new javax.swing.JTextField();
        jtfDiaChi = new javax.swing.JTextField();
        jtfSoTaiKhoan = new javax.swing.JTextField();
        jbtThem = new javax.swing.JButton();
        jbtXoa = new javax.swing.JButton();
        jbtCapNhat = new javax.swing.JButton();
        jtbThoat = new javax.swing.JButton();
        jbtTaiLai = new javax.swing.JButton();
        jbnTimKiem = new javax.swing.JButton();
        jbtClear = new javax.swing.JButton();

        setClosable(true);
        setIconifiable(true);
        setMaximizable(true);
        setTitle("Quản Lý Nhân Viên");
        addInternalFrameListener(new javax.swing.event.InternalFrameListener() {
            public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosing(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameOpened(javax.swing.event.InternalFrameEvent evt) {
                formInternalFrameOpened(evt);
            }
            public void internalFrameActivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeactivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeiconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameIconified(javax.swing.event.InternalFrameEvent evt) {
            }
        });

        jLabel1.setText("Mã Nhân Viên:");

        jLabel2.setText("Tên Nhân Viên:");

        jLabel3.setText("Bộ Phận");

        jLabel4.setText("Địa Chỉ:");

        jLabel5.setText("Điện Thoại:");

        jLabel6.setText("Email:");

        jLabel7.setText("Số Tài Khoản:");

        jLabel8.setText("Ngân Hàng:");

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Nhân Viên"));

        jtbNhanVien.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        jtbNhanVien.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jtbNhanVienMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jtbNhanVien);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 275, Short.MAX_VALUE)
        );

        jtfEmail.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtfEmailActionPerformed(evt);
            }
        });

        jtfMaNhanVien.setEditable(false);

        jtfSoTaiKhoan.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtfSoTaiKhoanActionPerformed(evt);
            }
        });

        jbtThem.setText("Thêm");
        jbtThem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtThemActionPerformed(evt);
            }
        });

        jbtXoa.setText("Xóa");
        jbtXoa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtXoaActionPerformed(evt);
            }
        });

        jbtCapNhat.setText("Cập Nhật");
        jbtCapNhat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtCapNhatActionPerformed(evt);
            }
        });

        jtbThoat.setText("Thoát");
        jtbThoat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtbThoatActionPerformed(evt);
            }
        });

        jbtTaiLai.setText("Tải Lại");
        jbtTaiLai.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtTaiLaiActionPerformed(evt);
            }
        });

        jbnTimKiem.setText("Tìm Kiếm");
        jbnTimKiem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbnTimKiemActionPerformed(evt);
            }
        });

        jbtClear.setText("Clear All");
        jbtClear.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtClearActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel8)
                                    .addComponent(jLabel7)
                                    .addComponent(jLabel5)
                                    .addComponent(jLabel1))
                                .addGap(26, 26, 26)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jtfMaNhanVien)
                                    .addComponent(jtfDienThoai)
                                    .addComponent(jtfNganHang, javax.swing.GroupLayout.DEFAULT_SIZE, 294, Short.MAX_VALUE)
                                    .addComponent(jtfSoTaiKhoan))
                                .addGap(91, 91, 91)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jLabel3)
                                        .addGap(52, 52, 52)
                                        .addComponent(jcbBoPhan, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel2)
                                            .addComponent(jLabel4)
                                            .addComponent(jLabel6))
                                        .addGap(18, 18, 18)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(layout.createSequentialGroup()
                                                .addComponent(jbnTimKiem, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGap(0, 0, Short.MAX_VALUE))
                                            .addComponent(jtfDiaChi)
                                            .addComponent(jtfTenNhanVien)
                                            .addComponent(jtfEmail, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 264, Short.MAX_VALUE)))))
                            .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(0, 0, Short.MAX_VALUE)
                                .addComponent(jbtTaiLai, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(27, 27, 27))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jbtClear)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jbtThem, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jbtXoa, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jbtCapNhat, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jtbThoat)
                        .addGap(33, 33, 33))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(jtfMaNhanVien, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5)
                            .addComponent(jtfDienThoai, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel8)
                            .addComponent(jtfNganHang, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel7)
                            .addComponent(jtfSoTaiKhoan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(jcbBoPhan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(jtfTenNhanVien, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(jtfDiaChi, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel6)
                            .addComponent(jtfEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jbtTaiLai)
                    .addComponent(jbnTimKiem))
                .addGap(16, 16, 16)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jbtClear)
                    .addComponent(jbtCapNhat, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jtbThoat, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jbtXoa, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jbtThem, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
public boolean KiemTraThongTinNhap(){
      boolean flag = true;
      if(jtfTenNhanVien.getText().length() == 0 || jtfDiaChi.getText().length() == 0
              || jtfDienThoai.getText().length() == 0|| jtfEmail.getText().length() == 0
              || jtfSoTaiKhoan.getText().length() == 0  || jtfNganHang.getText().length() == 0){
            return false;
      }
      return flag;
}
    public void loadcomboxBoPhan(){
        try {
            this.comboBoxModelLoaiNhanVien = new DefaultComboBoxModel();
            this.jcbBoPhan.setModel(comboBoxModelLoaiNhanVien);
            List<Bophan> ds = bophanDAO.layDanhSachBoPhan();
            for (int i = 0; i < ds.size(); i++) {
                Bophan bp = ds.get(i);
                this.comboBoxModelLoaiNhanVien.addElement(bp);
            }
        } catch (HibernateException ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage());
        }
    }
public int indexCbLoaiHangTuTable(Nhanvien nv){
    int ix = 0;
    for (int i = 0; i < this.jcbBoPhan.getItemCount(); i++) {
        Bophan bp = (Bophan) jcbBoPhan.getItemAt(i);
        if(bp.getMabophan() == nv.getBophan().getMabophan())
            return i;
    }
    return ix;
}
public void hienThiNhanVien(){
   
        jtbNhanVien.removeAll();
        dsNhanVien = nhanvienDAO.layDanhSachNhanVienTonTai();
        
        dtm.setNumRows(dsNhanVien.size());
        for(int i = 0; i<dsNhanVien.size(); i++){
            Nhanvien nv =  dsNhanVien.get(i);
            dtm.setValueAt(nv.getManhanvien(), i, 0);
            dtm.setValueAt(nv.getTennhanvien(), i, 1);
            dtm.setValueAt(nv.getBophan().getTenbophan(), i, 2);
            dtm.setValueAt(nv.getDiachi(), i, 3);
            dtm.setValueAt(nv.getDienthoai(), i, 4);
            dtm.setValueAt(nv.getEmail(), i, 5);
            dtm.setValueAt(nv.getSotaikhoan(), i, 6);
            dtm.setValueAt(nv.getNganhang(), i, 7);
        }
        //Hiển thị lên Table
        this.jtbNhanVien.setModel(dtm);
        this.jtbNhanVien.changeSelection(0, 0, false, false);
    
    }
    private void jtfEmailActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtfEmailActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jtfEmailActionPerformed

    private void jtfSoTaiKhoanActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtfSoTaiKhoanActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jtfSoTaiKhoanActionPerformed

    private void jbtCapNhatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtCapNhatActionPerformed
        // TODO add your handling code here:
        if(KiemTraThongTinNhap() == false){
            JOptionPane.showMessageDialog(this, "Chưa Nhập Đủ Thông Tin.", "Thông Báo", JOptionPane.WARNING_MESSAGE);
            return;
        }
        Nhanvien nv = nhanvienDAO.layThongTinNhanVien(jtfMaNhanVien.getText().trim());
        
        if(nv!=null){
            nv.setTennhanvien(jtfTenNhanVien.getText());
            Bophan bp  =  (Bophan) jcbBoPhan.getItemAt(jcbBoPhan.getSelectedIndex());
            nv.setBophan(bp);
           
            nv.setDiachi(jtfDiaChi.getText());
            nv.setDienthoai(jtfDienThoai.getText());
            nv.setEmail(jtfEmail.getText());
            nv.setSotaikhoan(jtfSoTaiKhoan.getText());
            nv.setNganhang(jtfNganHang.getText());
            boolean kq = nhanvienDAO.capNhatThongTinNhanVien(nv);
            if (kq == true) {
                hienThiNhanVien();
                JOptionPane.showMessageDialog(this, "Cập Nhật nhân viên thành công");
            } else {
                JOptionPane.showMessageDialog(this, "Cập Nhật nhân viên thất bại");
            }
        } 
    }//GEN-LAST:event_jbtCapNhatActionPerformed

    private void formInternalFrameOpened(javax.swing.event.InternalFrameEvent evt) {//GEN-FIRST:event_formInternalFrameOpened
        // TODO add your handling code here:
        loadcomboxBoPhan();
        hienThiNhanVien();
    }//GEN-LAST:event_formInternalFrameOpened

    private void jbtThemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtThemActionPerformed
        // TODO add your handling code here:
    if(KiemTraThongTinNhap() == false){
            JOptionPane.showMessageDialog(this, "Chưa Nhập Đủ Thông Tin.", "Thông Báo", JOptionPane.WARNING_MESSAGE);
            return;
    }
            
      Nhanvien nv = new Nhanvien();
      
      nv.setTennhanvien(jtfTenNhanVien.getText());
      Bophan bp  =  (Bophan) jcbBoPhan.getItemAt(jcbBoPhan.getSelectedIndex());
      nv.setBophan(bp);
      
      nv.setDiachi(jtfDiaChi.getText());
      nv.setDienthoai(jtfDienThoai.getText());
      nv.setEmail(jtfEmail.getText());
      nv.setSotaikhoan(jtfSoTaiKhoan.getText());
      nv.setNganhang(jtfNganHang.getText());
      nv.setKichhoat(true);
      nv.setMatkhau("0");
      //Kiểm tra mật khẩu
      boolean kq = nhanvienDAO.themNhanVien(nv);
        if (kq == true) {
            hienThiNhanVien();
            JOptionPane.showMessageDialog(this, "Thêm nhân viên mới thành công");
        } else {
            JOptionPane.showMessageDialog(this, "Thêm nhân viên mới thất bại");
        }    
    }//GEN-LAST:event_jbtThemActionPerformed

    private void jtbThoatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtbThoatActionPerformed
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_jtbThoatActionPerformed

    private void jtbNhanVienMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jtbNhanVienMouseClicked
        // TODO add your handling code here:
        int dong = this.jtbNhanVien.getSelectedRow();
        Nhanvien nv = dsNhanVien.get(dong);
        
        this.jtfMaNhanVien.setText(String.valueOf(nv.getManhanvien()));
        this.jtfTenNhanVien.setText(nv.getTennhanvien());
        jcbBoPhan.setSelectedIndex(indexCbLoaiHangTuTable(nv));
        this.jtfDiaChi.setText(String.valueOf(nv.getDiachi()));
        this.jtfDienThoai.setText(String.valueOf(nv.getDienthoai()));
        this.jtfEmail.setText(String.valueOf(nv.getEmail()));
        this.jtfSoTaiKhoan.setText(String.valueOf(nv.getSotaikhoan()));
        this.jtfNganHang.setText(String.valueOf(nv.getNganhang()));
    }//GEN-LAST:event_jtbNhanVienMouseClicked

    private void jbtXoaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtXoaActionPerformed
        // TODO add your handling code here:
        Nhanvien nv = nhanvienDAO.layThongTinNhanVien(jtfMaNhanVien.getText().trim());
        
        if(nv!=null){
            nv.setKichhoat(false);
            boolean kq = nhanvienDAO.capNhatThongTinNhanVien(nv);
            if (kq == true) {
                hienThiNhanVien();
                JOptionPane.showMessageDialog(this, "Xóa nhân viên thành công");
            } else {
                JOptionPane.showMessageDialog(this, "Xóa nhân viên thất bại");
            }
        }
    }//GEN-LAST:event_jbtXoaActionPerformed
  public boolean hienThiTimKiem() {

        dsNhanVien = nhanvienDAO.timKiemNhanVien(_TeamOjectNhanVien);
        if (dsNhanVien.isEmpty()) {
            return false;
        }
        jtbNhanVien.removeAll();

        dtm.setNumRows(dsNhanVien.size());
        for (int i = 0; i < dsNhanVien.size(); i++) {
            Nhanvien hh = dsNhanVien.get(i);
            dtm.setValueAt(hh.getManhanvien(), i, 0);
            dtm.setValueAt(hh.getTennhanvien(), i, 1);
            dtm.setValueAt(hh.getBophan().getTenbophan(), i, 2);
            dtm.setValueAt(hh.getDiachi(), i, 3);
            dtm.setValueAt(hh.getDienthoai(), i, 4);
            dtm.setValueAt(hh.getEmail(), i, 5);
            dtm.setValueAt(hh.getSotaikhoan(), i, 6);
            dtm.setValueAt(hh.getNganhang(), i, 7);
       
        }
        //Hiển thị lên Table
        this.jtbNhanVien.setModel(dtm);
        this.jtbNhanVien.changeSelection(0, 0, false, false);
        return true;
    }
    private void jbnTimKiemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbnTimKiemActionPerformed
        // TODO add your handling code here:

        //gan cac gia tri da chon cho _TeampOb....

        _TeamOjectNhanVien = new Nhanvien();
        if(jtfMaNhanVien.getText().length() == 0)
            _TeamOjectNhanVien.setManhanvien(-1);
        else
            _TeamOjectNhanVien.setManhanvien(Integer.parseInt(jtfMaNhanVien.getText()));
        
        if (jtfDiaChi.getText().length() == 0) {
            _TeamOjectNhanVien.setDiachi("");
        } else {
            _TeamOjectNhanVien.setDiachi(jtfDiaChi.getText());
        }
        
        if (jtfDienThoai.getText().length() == 0) {
            _TeamOjectNhanVien.setDienthoai("");
        } else {
            _TeamOjectNhanVien.setDienthoai(jtfDienThoai.getText());
        }

        if (jtfNganHang.getText().length() == 0) {
            _TeamOjectNhanVien.setNganhang("");
        } else {
            _TeamOjectNhanVien.setNganhang(jtfNganHang.getText());
        }
        
        if (jtfEmail.getText().length() == 0) {
            _TeamOjectNhanVien.setEmail("");
        } else {
            _TeamOjectNhanVien.setEmail(jtfEmail.getText());
        }

        if (jtfSoTaiKhoan.getText().length() == 0) {
            _TeamOjectNhanVien.setSotaikhoan("");
        } else {
            _TeamOjectNhanVien.setSotaikhoan(jtfSoTaiKhoan.getText());
        }
        
        if (jtfTenNhanVien.getText().length() == 0) {
            _TeamOjectNhanVien.setTennhanvien("");
        } else {
            _TeamOjectNhanVien.setTennhanvien(jtfTenNhanVien.getText());
        }
        Bophan lhh = (Bophan) jcbBoPhan.getItemAt(jcbBoPhan.getSelectedIndex());
        _TeamOjectNhanVien.setBophan(lhh);

       
        _TeamOjectNhanVien.setKichhoat(true);

        if (hienThiTimKiem() == false) {
            JOptionPane.showMessageDialog(this, "Không có nhân viên.");
        } else {
        }


    }//GEN-LAST:event_jbnTimKiemActionPerformed

    private void jbtClearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtClearActionPerformed
        // TODO add your handling code here:
        jtfDiaChi.setText("");
        jtfDienThoai.setText("");
        jtfEmail.setText("");
        jtfNganHang.setText("");
        jtfSoTaiKhoan.setText("");
        jtfTenNhanVien.setText("");
    }//GEN-LAST:event_jbtClearActionPerformed

    private void jbtTaiLaiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtTaiLaiActionPerformed
        // TODO add your handling code here:
        hienThiNhanVien();
    }//GEN-LAST:event_jbtTaiLaiActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton jbnTimKiem;
    private javax.swing.JButton jbtCapNhat;
    private javax.swing.JButton jbtClear;
    private javax.swing.JButton jbtTaiLai;
    private javax.swing.JButton jbtThem;
    private javax.swing.JButton jbtXoa;
    private javax.swing.JComboBox jcbBoPhan;
    private javax.swing.JTable jtbNhanVien;
    private javax.swing.JButton jtbThoat;
    private javax.swing.JTextField jtfDiaChi;
    private javax.swing.JTextField jtfDienThoai;
    private javax.swing.JTextField jtfEmail;
    private javax.swing.JTextField jtfMaNhanVien;
    private javax.swing.JTextField jtfNganHang;
    private javax.swing.JTextField jtfSoTaiKhoan;
    private javax.swing.JTextField jtfTenNhanVien;
    // End of variables declaration//GEN-END:variables
}
